<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>组件化改写 TodoList</title>
  <script src='./vue.js'></script>
</head>
<body>
  <div id="app">
    <input type="text" v-model="inputVal"/>
    <button v-on:click="handleBtnClick">提交</button>
    <ul>
      <!-- <li v-for="item of List">{{item}}</li> -->
      <!-- 给自组件传递数据 v-bind -->
      <todo-item v-bind:content="item" v-for='item of List' :key="item"></todo-item>
    </ul>
  </div>

  <script>
    // 全局组件的使用
    // 定义一个全局组件TodoItem
    // 接收父组件传递的数据，放在props里
    // Vue.component('TodoItem', {
    //   props: ['content'],
    //   template: '<li>{{content}}</li>'
    // })

    // 局部组件的使用
    var TodoItem = {
      props: ['content'],
      template: '<li>{{content}}</li>'
    }

    var app = new Vue({
      el: '#app',
      components: {TodoItem},
      data: {
        List: [],
        inputVal: ''
      },
      methods: {
        handleBtnClick:function() {
          // alert('3333')
          this.List.push(this.inputVal)
          this.inputVal = ''
        }
      }
    });
  
  
  </script>
  
</body>
</html>